<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="">
        <el-breadcrumb-item>
          <div class="div1">基本配置</div>
        </el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/lineChinnel' }">
          <div class="div2">入线渠道管理</div>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 面包屑导航 -->
    <!-- 添加客户等级 -->
    <div class="content">
      <p class="header">添加入线渠道</p>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="入线渠道">
          <el-input
            maxlength="128"
            v-model="formInline.name"
            placeholder="请输入入线渠道名称"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="部门选择">
          <el-select
            v-model="formInline.team"
            multiple
            placeholder="选择部门"
            clearable
          >
            <el-option
              v-for="itemsS in logisticsCont"
              :key="itemsS.dictId"
              :label="itemsS.dictName"
              :value="itemsS.dictId"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button
            type="primary"
            @click="onSubmit"
            v-if="parArray.indexOf('addline') != -1"
            >添加入线渠道</el-button
          >
          <el-button type="primary" @click="searchEvent">搜索</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 添加客户等级 -->
    <!-- 管理客户等级 -->
    <div class="manage">
      <p class="header">管理入线渠道</p>
      <div class="table">
        <el-table :data="tableData.list">
          <el-table-column type="index" label="序号" width="100">
          </el-table-column>
          <el-table-column min-width="150px" scope="scope" label="入线渠道名称">
            <template slot-scope="scope">
              <el-input v-model="scope.row.name"></el-input>
            </template>
          </el-table-column>

          <!-- <el-table-column min-width="150px" label="部门权限" width="400">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.salesAuthorityIds"
                multiple
                placeholder="选择部门"
                clearable
              >
                <el-option
                  v-for="itemsS in logisticsCont"
                  :key="itemsS.dictId"
                  :label="itemsS.dictName"
                  :value="itemsS.dictId"
                ></el-option>
              </el-select>
            </template>
          </el-table-column> -->

          <el-table-column
            min-width="160px"
            prop="createdTime"
            label="更新时间"
          ></el-table-column>
          <el-table-column label="操作" width="500">
            <template slot-scope="scope">
              <div class="optain">
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="保存"
                  placement="top-start"
                >
                  <el-button
                    type="text"
                    @click="preservation(scope.row)"
                    v-if="parArray.indexOf('bcline') != -1"
                  >
                    <span>保存</span>
                    <!-- <img src="../../assets/baocun.png" alt="" /> -->
                  </el-button>
                </el-tooltip>
                <!-- <el-tooltip class="item" effect="dark" content="推荐按钮类似关闭,点击后该入线渠道不可被选" placement="top-start">
																	<p v-if='parArray.indexOf("addline")!=-1'><img src="../../assets/intro.png" alt=""></p>
																</el-tooltip>		 -->
                <!-- <el-tooltip
                  class="item"
                  effect="dark"
                  content="置顶"
                  placement="top-start"
                >
                  <p v-if="parArray.indexOf('zdlin') != -1">
                    <span>置顶</span>
                  </p>
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="向下移动"
                  placement="top-start"
                >
                  <p v-if="parArray.indexOf('linebotton') != -1">
                    <span>下移</span>
                  </p>
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="向上移动"
                  placement="top-start"
                >
                  <p v-if="parArray.indexOf('linetop') != -1">
                    <span>上移</span>
                  </p>
                </el-tooltip> -->
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="删除"
                  placement="top-start"
                >
                  <el-button
                    type="text"
                    style="color: red"
                    v-if="parArray.indexOf('linedelect') != -1"
                    @click="delect(scope.row, scope.$index)"
                  >
                    <span>删除</span>
                  </el-button>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页start -->
        <div class="page" v-if="tableData.totalNum >= 10">
          <div class="block">
            <span class="demonstration">共{{ tableData.totalPage }}页</span>
            <span class="demonstration">总共{{ tableData.totalNum }}条</span>
            <el-pagination
              @current-change="handleCurrentChange"
              :current-page.sync="pageNo"
              :page-size="1"
              layout="prev, pager, next"
              prev-text="上一页"
              next-text="下一页"
              :total="tableData.totalPage"
            >
            </el-pagination>
          </div>
        </div>
        <!-- 分页end -->
      </div>
    </div>
    <!-- 管理客户等级 -->
  </div>
</template>

<script>
export default {
  data () {
    return {
      formInline: {
        name: "",
        // team: [],
      },
      tableData: [],
      pageNo: 1,
      limits: "",
      parArray: [],
      // logisticsCont: [],
    };
  },
  created () {
    this.listAxios("1");
    // this.groupEvent();
    // 权限设定判断 normsCode
    this.limits = JSON.parse(sessionStorage.getItem("limit"));
    const params = this.limits.buttonTreeDto.filter(
      (item) => item.menuCode === "lineChinnelCode"
    );
    params[0].buttonList.forEach((item) => {
      this.parArray.push(item.code);
    });
    // 权限设定判断 normsCode
  },
  activated () {
    // this.listAxios("1");
    // this.groupEvent();
  },
  methods: {
    // 列表
    listAxios () {
      this.axios
        .post("/order/comm/customerditch/list", {
          pageNo: this.pageNo,
          pageSize: 10,
          name: this.formInline.name,
          // salesAuthorityIds: this.formInline.team,
        })
        .then((res) => {
          if (res.code == 0) {
            this.tableData = res.data;
          } else {
            this.$message.error(res.message);
          }
        });
    },
    searchEvent () {
      this.pageNO = 1;
      this.pageSize = 10;
      this.listAxios();
    },
    // 重置
    reset () {
      this.formInline.name = ""
      this.listAxios();

    },
    /***分页查询***/
    handleCurrentChange (val) {
      this.pageNo = val;
      this.listAxios();
    },
    // // 部门下拉框
    // groupEvent () {
    //   this.axios
    //     .get("/sys/v1/common/by/group?groupId=" + "sales_authority", {
    //       headers: {
    //         isLoading: false,
    //       },
    //     })
    //     .then((res) => {
    //       if (res.code == 0) {
    //         this.logisticsCont = res.data;
    //       } else {
    //         this.$message.error(res.message);
    //       }
    //     });
    // },
    //**入线渠道设定**//
    onSubmit () {
      if (this.formInline.name == "") {
        this.$message.error("名称不能为空");
      }
      //  else if (this.formInline.team.length == 0) {
      //   this.$message.error("部门不能为空");
      // } 
      else {
        this.axios
          .post(
            "/order/comm/customerditch/add",
            {
              createdBy: sessionStorage.getItem("user_id"),
              name: this.formInline.name,
              // salesAuthorityIds: this.formInline.team,
            },
            {
              headers: {
                isloading: false,
              },
            }
          )
          .then((res) => {
            // console.log(res);
            if (res.code == 0) {
              this.$message.success("添加成功");
              this.formInline.name = "";
              // this.formInline.team = [];
              this.listAxios();
            } else {
              this.$message.error(res.message);
            }
          });
      }
    },
    //**入线渠道设定**//
    /***删除数据对接***/
    delect (row, index) {
      this.$confirm("确定要删除该入线渠道吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.axios
            .get("/order/comm/customerditch/delete?id=" + row.id)
            .then((res) => {
              if (res.code == 0) {
                // this.tableData.list.splice(index, 1);
                this.listAxios("1");
                this.$message.success("删除成功");
              } else {
                this.$message.error(res.message);
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    /***删除数据对接***/

    /***修改数据对接***/
    preservation (row) {
      this.axios
        .post("/order/comm/customerditch/update", {
          id: row.id,
          updatedBy: sessionStorage.getItem("user_id"),
          name: row.name,
          salesAuthorityIds: row.salesAuthorityIds,
        })
        .then((res) => {
          this.listAxios("1");
          if (res.code == 0) {
            this.$message.success("修改成功");
          } else {
            this.$message.error(res.message);
          }
        });
    },
    /***修改数据对接***/
  },
};
</script>

<style scoped lang="scss">
.div1 {
  margin-left: -16px;
  background: url(../../assets/breadcrumb2.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}

.div2 {
  margin-left: -16px;
  background: url(../../assets/breadcrumb1.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #fff;
}

.content {
  padding: 10px;
  background: #fff;

  .el-button {
    padding: 7px 20px;
  }
}

.header {
  font-size: 16px;
  color: #2d7edf;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.demo-form-inline {
  margin-top: 10px;
}

/deep/.el-input__inner {
  height: 30px;
  line-height: 30px;
}

.manage {
  margin-top: 20px;
  padding: 10px;
  background: #fff;
}

/deep/.has-gutter .cell {
  text-align: center;
  color: #2d7ddf;
}

/deep/.cell {
  text-align: center;
}

/deep/.el-table__row .cell {
}

.optain {
  width: 100%;
  text-align: center;
}

.name {
  font-size: 16px;
  color: #2d7edf;
  margin: 10px 0;
}

.optain {
  p {
    display: inline-block;
    margin-left: 20px;

    img {
      width: 20px;
      height: 20px;
    }
  }
}

.page {
  margin: 20px 0;
  text-align: right;
  width: 100%;

  span {
    font-size: 15px;
    color: #888;
    display: inline-block;
    margin-left: 10px;
    margin-top: -2px;
    vertical-align: middle;
  }

  .el-pagination {
    display: inline-block;
    vertical-align: middle;
  }
}
</style>
